FROM registry.cn-hangzhou.aliyuncs.com/acs/maven:3-jdk-8 AS builder-mvn

#Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)
#Maven home: /usr/share/maven
#Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
#Default locale: en, platform encoding: UTF-8
#OS name: "linux", version: "5.10.47-linuxkit", arch: "amd64", family: "unix"

ENV MY_HOME=/usr/src/app
RUN mkdir -p $MY_HOME
WORKDIR $MY_HOME
ADD pom.xml $MY_HOME

# get all the downloads out of the way
RUN ["/usr/local/bin/mvn-entrypoint.sh","mvn","verify","clean","--fail-never"]

# add source
ADD . $MY_HOME

# run maven verify
#RUN ["/usr/local/bin/mvn-entrypoint.sh","mvn","package","-DskipTests"]
RUN ["/usr/local/bin/mvn-entrypoint.sh","mvn","verify","-DskipTests"]

#FROM openjdk:8u302-jre-buster
FROM openjdk:8-bullseye
#FROM openjdk:8-jdk-alpine
COPY --from=builder-mvn /usr/src/app/target/*.jar /app/app.jar
COPY --from=builder-mvn /usr/src/app/jmx-exporter /app/jmx-exporter
WORKDIR /app


#ENV JAVA_OPTS="-XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMPercentage=75.0 -XX:InitialRAMPercentage=75.0 -XX:MinRAMPercentage=75.0"
ENV APM_OPTS=""
#ENV SERVER_PORT 8080
#
#EXPOSE ${SERVER_PORT}

ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -javaagent:./jmx-exporter/jmx_prometheus_javaagent-0.16.1.jar=8080:./jmx-exporter/config.yaml -Djava.security.egd=file:/dev/urandom ${APM_OPTS} -jar /app/app.jar" ]